#include "rand.h"

namespace gecko
{

	RandomNumberGenerator::RandomNumberGenerator( unsigned int seed )
	{
		m_rnd = seed;
	}

	int RandomNumberGenerator::Generate( int from, int to )
	{
		if (to < from) // from should be less than to
		{
			int temp = to;

			to = from;
			from = temp;
		}
		else if (to == from)
		{
			return to;
		}

		m_rnd = (m_rnd * MULTIPLIER + INCREMENT) & 0xFFFFFF;

		float fTmp = (float)m_rnd / 16777216.0f;

		return (int) ((fTmp * (to - from + 1)) + from);
	}

	unsigned int RandomNumberGenerator::GetSeed()
	{
		return m_rnd;
	}

	float RandomNumberGenerator::GenerateNormalised()
	{
		static const short RandMax = 0x7fff;

		int rnd = Generate(0, RandMax);

		return (float)rnd / RandMax;
	}

}